package didispace.controller;

import didispace.module.UsersEntity;
import didispace.service.UserService;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

  @Resource
  private UserService userService;

  @PostMapping ("/list")
  public List<UsersEntity> getUserList(@RequestBody UsersEntity usersEntity) {
    List<UsersEntity> userList = userService.getUserList(usersEntity);
    return userList;
  }



  @CrossOrigin
  @PostMapping("/login")
  public UsersEntity loginTo(@RequestBody UsersEntity usersEntity, HttpSession session) {

    UsersEntity users = userService.userLogin(usersEntity.getUserAcount(), usersEntity.getUserPassword());
    System.out.println(users);
    if (users != null && !"".equals(users)) {
      String u_stutas = users.getUserStatus();
      if (!u_stutas.equals("1")) {
        return null;
      }
    }

    return users;

  }
}
